package com.zb.code.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.AccounLoginInfo;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjCodeUserAddressChangeLogService;
import com.zb.service.ZjCodeUserRegisterService;
import com.zb.utils.TokenUtil;
import com.zb.vo.CodeRegisterAddressVo;
import com.zb.vo.CodeUserRegisterVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * <p>
 * 编码用户登记表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-09-04
 */
@Api(tags = "编码用户登记类接口")
@RestController
@RequestMapping("/code/userRegister")
public class ZjCodeUserRegisterController {
    @Resource
    private ZjCodeUserRegisterService codeUserRegisterService;
    @Resource
    private ZjCodeUserAddressChangeLogService codeUserAddressChangeLogService;

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.UPDATE, remark = "编码档案-编码列表 - 编码关联用户登记")
    @ApiOperation("保存编码关联用户登记")
    @PostMapping("/saveCodeRegister/{codeId}")
    public Result saveCodeRegister(HttpServletRequest request, @PathVariable @ApiParam(value = "编码ID", required = true) Long codeId,
                               @RequestBody @Valid CodeUserRegisterVo userRegisterVo) {
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        codeUserRegisterService.saveCodeRegister(loginInfo, codeId, userRegisterVo);
        return Result.success("编码关联用户登记成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, type = OperationLogType.UPDATE, remark = "编码档案-编码列表 - 编码关联用户登记")
    @ApiOperation("变更用户登记地址")
    @PutMapping("/updateCodeRegisterAddress/{codeId}")
    public Result updateCodeRegisterAddress(HttpServletRequest request, @PathVariable @ApiParam(value = "编码ID", required = true) Long codeId,
                                            @RequestBody @Valid CodeRegisterAddressVo addressVo) {
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        codeUserRegisterService.updateCodeRegisterAddress(loginInfo, codeId, addressVo);
        return Result.success("编码登记地址变更成功");
    }

    @ApiOperation("获取变更用户登记地址列表")
    @PostMapping("/getCodeRegisterAddressList/{codeId}")
    public Result getCodeRegisterAddressList(@PathVariable @ApiParam(value = "编码ID", required = true) Long codeId,
                                             @RequestBody PageUtil pageUtil) {
        return Result.success("获取变更用户登记地址列表成功").data(codeUserAddressChangeLogService.getList(codeId, pageUtil));
    }





}
